package info.hexin.json.serialize.render;

import info.hexin.json.serialize.JsonRender;
import info.hexin.json.serialize.JsonSerializeConfig;
import info.hexin.json.serialize.StringWrite;

public class ArrayRender implements JsonRender {
    public static ArrayRender instance = new ArrayRender();

    @Override
    public void render(Object object, StringWrite write) {
        Object[] array = (Object[]) object;
        write.append('[');
        for (int i = 0, k = 0; i < array.length; i++) {
            Object o = array[i];
            if (o == null) {
                continue;
            }
            if (k++ > 0) {
                write.append(',');
            }
            JsonRender render = JsonSerializeConfig.getRender(o.getClass());
            render.render(o, write);
        }
        write.append(']');
    }
}
